package net.empego.cdi.testapp.util;

import javax.ejb.EJB;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;

import net.empego.db.SiteMapDAO;

/**
 * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans
 * 
 * <p>
 * Example injection on a managed bean field:
 * </p>
 * 
 * <pre>
 * &#064;Inject
 * private EntityManager em;
 * </pre>
 */
public class Resources {

	// @PersistenceContext(name = "primary-non-jta")
	// // @PersistenceContext(name = "primary-jta")
	// private EntityManager em;

	@PersistenceUnit(name = "primary-non-jta")
	private EntityManagerFactory emf;

	// @Produces
	// @ExecutionScoped
	// @NonJtaPersistenceContext
	// public EntityManager getEntityManager() {
	// final EntityManager em = emf.createEntityManager();
	// if (em.getTransaction().isActive() == false) {
	// em.getTransaction().begin();
	// }
	// return em;
	// }

	@Produces
	@EJB
	private SiteMapDAO siteMapDao;

}
